package com.cloud.async.business.core;

import com.cloud.async.business.body.FutureResult;
import com.cloud.async.error.ErrorHandler;
import com.cloud.async.monitor.ResultHandlerMonitor;
import com.cloud.async.result.core.AsyncResult;

public abstract class BaseAsyncResultHandler extends AsyncTaskLifecycle implements AsyncResult {

    /**
     * 超时时间
     */
    protected Long localMilliSecond;

    private AsyncTaskLifecycle asyncBusiness;

    protected ErrorHandler errorHandler;

    protected ResultHandlerMonitor resultHandlerMonitor;

    public BaseAsyncResultHandler(Long localMilliSecond, AsyncTaskLifecycle asyncBusiness,
                                  ErrorHandler errorHandler, ResultHandlerMonitor resultHandlerMonitor) {
        this.localMilliSecond = localMilliSecond;
        this.asyncBusiness = asyncBusiness;
        this.errorHandler = errorHandler;
        this.resultHandlerMonitor = resultHandlerMonitor;
    }

    @Override
    protected boolean isTaskActive(String taskId) {
        return asyncBusiness.isTaskActive(taskId);
    }

    @Override
    protected void releaseTask(String taskId) {
        asyncBusiness.releaseTask(taskId);
    }

    @Override
    protected FutureResult getTaskResult(String taskId) {
        return asyncBusiness.getTaskResult(taskId);
    }
}
